import { defineStore } from 'pinia'
import api from '@/api/api'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: {},
    isLoggedIn: null,
    localStorageName:"",
    themColor:''
  }),

  actions: {
    login() {// 模拟登录验证
      if(localStorage.getItem(this.localStorageName)){
        let verLoginData = JSON.parse(localStorage.getItem(this.localStorageName))
        if(verLoginData.loginTimeStamp > verLoginData.loginTimeStamp+43200){/* 登录有效时间12小时 */
          localStorage.removeItem(this.localStorageName)
        }else{
          this.user = JSON.parse(localStorage.getItem(this.localStorageName));
          this.isLoggedIn = true
        }
      }else{
        this.isLoggedIn = false
      }
    },
    logout() {
      console.log("logout")
      this.user = null
      this.isLoggedIn = false
    },
  },
})